//=============================================================================
// MP7M Alt Fire that shoots healing projectiles
//=============================================================================
class M7A3MAltFire extends SRKFShotgunFire;
var KFPlayerReplicationInfo KFPRI;
function PlayFireEnd(){}

event ModeDoFire()
{
	if (Instigator == None)
		return;
		
	KFPRI = KFPlayerReplicationInfo(Instigator.PlayerReplicationInfo);
	if (KFPRI != none && (KFPRI.ClientVeteranSkill.Name == 'SRVetFieldMedic' && 
		KFPRI.ClientVeteranSkillLevel > 10))
	{
		FireRate=0.25;
		if (KFPRI.ClientVeteranSkillLevel == 11)
			AmmoPerFire=125;
		else
			AmmoPerFire=83;
		bWaitForRelease=False;
	}
	else
	{
		FireRate=Default.FireRate;
		AmmoPerFire=Default.AmmoPerFire;
		bWaitForRelease=Default.bWaitForRelease;
	}
	
	Super.ModeDoFire();
}

function DoFireEffect()
{
	local Vector StartProj, StartTrace, X,Y,Z;
	local Rotator R, Aim;
	local Vector HitLocation, HitNormal;
	local Actor Other;
	local int p;
	local int SpawnCount;
	local float theta;

	Instigator.MakeNoise(1.0);
	Weapon.GetViewAxes(X,Y,Z);

	StartTrace = Instigator.Location + Instigator.EyePosition();// + X*Instigator.CollisionRadius;
	StartProj = StartTrace + X*ProjSpawnOffset.X;
	if ( !Weapon.WeaponCentered() && !KFWeap.bAimingRifle )
		StartProj = StartProj + Weapon.Hand * Y*ProjSpawnOffset.Y + Z*ProjSpawnOffset.Z;

	// check if projectile would spawn through a wall and adjust start location accordingly
	Other = Weapon.Trace(HitLocation, HitNormal, StartProj, StartTrace, false);

// Collision attachment debugging
/*   if( Other.IsA('ROCollisionAttachment'))
	{
		log(self$"'s trace hit "$Other.Base$" Collision attachment");
	}*/

	if (Other != None)
	{
		StartProj = HitLocation;
	}

	Aim = AdjustAim(StartProj, AimError);

	// Don't want to spawn the same projectile count as our load - Ramm
	SpawnCount = Max(1, ProjPerFire);

	switch (SpreadStyle)
	{
	case SS_Random:
		X = Vector(Aim);
		for (p = 0; p < SpawnCount; p++)
		{
			R.Yaw = Spread * (FRand()-0.5);
			R.Pitch = Spread * (FRand()-0.5);
			R.Roll = Spread * (FRand()-0.5);
			SpawnProjectile(StartProj, Rotator(X >> R));
		}
		break;
	case SS_Line:
		for (p = 0; p < SpawnCount; p++)
		{
			theta = Spread*PI/32768*(p - float(SpawnCount-1)/2.0);
			X.X = Cos(theta);
			X.Y = Sin(theta);
			X.Z = 0.0;
			SpawnProjectile(StartProj, Rotator(X >> Aim));
		}
		break;
	default:
		SpawnProjectile(StartProj, Aim);
	}
}

simulated function bool AllowFire()
{
	if(KFWeapon(Weapon).bIsReloading)
		return false;
	if(KFPawn(Instigator).SecondaryItem!=none)
		return false;
	if(KFPawn(Instigator).bThrowingNade)
		return false;

	return M7A3MMedicGun(Weapon).HealAmmoCharge >= AmmoPerFire;
}

defaultproperties
{
     maxVerticalRecoilAngle=1500
     maxHorizontalRecoilAngle=900
     FireAimedAnim="Fire_Iron"
     StereoFireSound=SoundGroup'KF_MP7Snd.Medicgun_FireST'
     ProjPerFire=1
     bAttachSmokeEmitter=True
     TransientSoundVolume=2.000000
     TransientSoundRadius=500.000000
     FireSound=SoundGroup'KF_MP7Snd.Medicgun_Fire'
     NoAmmoSound=Sound'KF_PumpSGSnd.SG_DryFire'
     FireRate=0.500000
     AmmoPerFire=250
     ShakeRotMag=(X=50.000000,Y=50.000000,Z=400.000000)
     ShakeRotRate=(X=12500.000000,Y=12500.000000,Z=12500.000000)
     ShakeRotTime=5.000000
     ShakeOffsetMag=(X=6.000000,Y=2.000000,Z=10.000000)
     ShakeOffsetRate=(X=1000.000000,Y=1000.000000,Z=1000.000000)
     ShakeOffsetTime=3.000000
     ProjectileClass=Class'PerksSimHostOrg.M7A3MHealinglProjectile'
     BotRefireRate=0.250000
     FlashEmitterClass=Class'ROEffects.MuzzleFlash1stKar'
     aimerror=1.000000
     Spread=0.000000
}
